<template>
    <a-modal
        class="box"
        :visible="visible"
        title="新增计划外招标"
        :width="1200"
        @cancel="handleCancel()"
    >
        <a-spin :spinning="loading">
            <a-form-model ref="form"
                          style="transform:translateX(25%)"
                          :labelCol="{lg: {span: 5}, sm: {span:5}}"
                          :wrapperCol="{lg: {span: 17}, sm: {span: 17} }"
                          :rules="rules" :model="queryParam">
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="所属分公司" prop="branchCompanyId">
                            <SelectSubCompany placeholder="请选择" v-model="queryParam.branchCompanyId"></SelectSubCompany>
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="项目名称" prop="projectId">
                            <SelectProject
                                v-if="visible"
                                placeholder="请选择"
                                v-model="queryParam.projectId"
                                :form="queryParam"
                                :isClear="false"
                                :isEdit="true"
                                keyValue="branchCompanyId"
                            ></SelectProject>
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="分包商选择方式" prop="subcontractorsSelect">
                            <a-select placeholder="请选择" v-model="queryParam.subcontractorsSelect">
                                <a-select-option v-for="item in subcontractor" :key="item.id" :value="item.id">
                                    {{ item.name }}
                                </a-select-option>
                            </a-select>
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="分包方式" prop="branchPackMode">
                            <a-select placeholder="请选择" default-value="0" v-model="queryParam.branchPackMode"
                            >
                                <a-select-option v-for="item in subcontractingMethod" :value="item.id" :key="item.id">
                                    {{ item.name }}
                                </a-select-option>
                            </a-select>
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="实际招标完成时间" prop="biddingCompleteTime">
                            <a-date-picker type="date" v-model="queryParam.biddingCompleteTime"
                                           valueFormat="YYYY-MM-DD" />
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="招标完成情况说明" prop="biddingCompleteRemark">
                            <BaseInput v-model.trim="queryParam.biddingCompleteRemark"
                                       placeholder="请输入" />
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="后期工作安排" prop="workArrangement">
                            <BaseInput v-model.trim="queryParam.workArrangement" placeholder="请输入" />
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="未按计划招标情况说明" prop="noPlanBiddingRemark">
                            <BaseInput v-model.trim="queryParam.noPlanBiddingRemark"
                                       placeholder="请输入" />
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="拟定队伍数量" prop="teamsNum">
                            <BaseInputNumber v-model.trim="queryParam.teamsNum"
                                             placeholder="请输入" />
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="分包工程招标内容" prop="branchProjectBiddingContent">
                            <BaseTextarea v-model.trim="queryParam.branchProjectBiddingContent" placeholder="请输入" />
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col span="12">
                        <a-form-model-item label="附件">
                            <b-upload uploadType="single" business-code="LCM16"
                                      :file-list.sync="queryParam.outPlanFileInfoVo"></b-upload>
                        </a-form-model-item>
                    </a-col>
                </a-row>
            </a-form-model>
        </a-spin>
        <template slot="footer page-btn-right-top">
            <a-button key="back" @click="handleCancel()">取消</a-button>
            <a-button :loading="loading" type="primary" @click="handleOk(queryParam,'DRAFT')">保存</a-button>
            <a-button :loading="loading" type="primary" @click="handleOk(queryParam,'PAST')">提交</a-button>
        </template>
    </a-modal>
</template>

<script>
import { getDropDown2 } from '@/api/dropDown'
import { addOutPlan, getCompleteDetails } from '@/api/legal'
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'

export default {
    name: 'addOutPlanBidding',
    components: { SelectSubCompany, SelectProject },
    props: {
        visible: {
            type: Boolean,
            default: () => false
        },
        form: {
            type: Object,
            default: () => {
            }
        }
    },
    data() {
        return {
            loading: false,
            queryParam: {
                outPlanFileInfoVo: {},
                'branchCompanyId': '',
                'projectId': '',
                'subcontractorsSelect': null,
                'branchPackMode': null,
                'biddingCompleteTime': '',
                'noPlanBiddingRemark': '',
                'teamsNum': '',
                'branchProjectBiddingContent': ''
            },
            rules: {
                branchCompanyId: [{ required: true, message: '请选择所属分公司', trigger: 'change' }],
                projectId: [{ required: true, message: '请选择项目名称', trigger: 'change' }],
                subcontractorsSelect: [{ required: true, message: '请选择分包商选择方式', trigger: 'change' }],
                branchPackMode: [{ required: true, message: '请选择分包方式', trigger: 'change' }],
                biddingCompleteTime: [{ required: true, message: '请选择实际招标完成时间', trigger: 'change' }],
                biddingCompleteRemark: [{ required: true, message: '请输入招标完成情况说明', trigger: 'change' }],
                workArrangement: [{ required: true, message: '请输入后期的工作安排', trigger: 'change' }],
                noPlanBiddingRemark: [{ required: true, message: '请输入未按计划招标情况说明', trigger: 'change' }],
                teamsNum: [{ required: true, message: '请输入拟定的队伍数量', trigger: 'change' }],
                branchProjectBiddingContent: [{ required: true, message: '请输入分包工程招标内容', trigger: 'change' }]
            },
            subcontractor: [],
            subcontractingMethod: []
        }
    },
    watch: {
        visible(val) {
            if (val && this.form) {
                getCompleteDetails({ id: this.form.id }).then((res) => {
                    if (res.code === 200) {
                        this.queryParam = res.data
                        this.queryParam.branchCompanyId = res.data.projectInfo.branchCompanyId
                        this.queryParam.projectId = res.data.projectInfo.projectId
                        this.queryParam.subcontractorsSelect = res.data.biddingPlanDerails.subcontractorsSelectId
                        this.queryParam.branchPackMode = res.data.biddingPlanDerails.branchPackModeId
                        this.queryParam.biddingCompleteTime = res.data.biddingPlanCompleteDetails.biddingCompleteTime
                        this.queryParam.biddingCompleteRemark = res.data.biddingPlanCompleteDetails.biddingCompleteRemark
                        this.queryParam.workArrangement = res.data.biddingPlanDerails.workArrangement

                        this.queryParam.noPlanBiddingRemark = res.data.biddingPlanDerails.information
                        this.queryParam.teamsNum = res.data.biddingPlanDerails.ranksNum
                        this.queryParam.branchProjectBiddingContent = res.data.biddingPlanDerails.biddingContent
                        this.$console(this.queryParam)
                    }
                })
            } else {
                this.queryParam = {
                    outPlanFileInfoVo: {},
                    'branchCompanyId': '',
                    'projectId': '',
                    'subcontractorsSelect': null,
                    'branchPackMode': null,
                    'biddingCompleteTime': '',
                    'noPlanBiddingRemark': '',
                    'teamsNum': '',
                    'branchProjectBiddingContent': ''
                }
            }
        }
    },
    created() {
        this.getSubcontractor()
        this.getSubcontractingMethod()
    },
    methods: {
        handleCancel() {
            this.$emit('update:visible', false)
            this.$refs.form.clearValidate()
            this.queryParam = {}
        },
        async handleOk(subQueryParam, status) {
            const form = this.$refs.form
            form.validate(async (valid) => {
                if (!valid) {
                    return this.$message.info('信息不完整')
                } else {
                    subQueryParam.auditStatusEnum = status
                    this.loading = true
                    let res = await addOutPlan(subQueryParam)
                    this.loading = false
                    if (res.code === 200) {
                        this.$message.success('新增成功')
                        this.$emit('ok')
                        this.handleCancel()
                    } else {
                        this.$message.error('提交失败')
                    }
                }
            })
        },
        getSubcontractor() {
            let query = { type: 1 }
            getDropDown2({ query: query }).then(res => {
                this.subcontractor = res.data
            })
        },
        getSubcontractingMethod() {
            let query = { type: 0 }
            getDropDown2({ query: query }).then(res => {
                this.subcontractingMethod = res.data
            })
        }
    }
}
</script>

<style lang="less" scoped>
/deep/ .ant-modal-header {
    text-align: center;
}

/deep/ .ant-modal-header .ant-modal-title {
    font-weight: 800;
}
</style>
